/*
 * AS3 MultiTouch Client
 *
 * DragBehaviour - Moves the object to the cursor position  
 *
 * Copyright 2008 Artifacts - Fine Software Development
 * http://www.artifacts.de
 * Author: Michael Markowski (m.markowski@artifacts.de)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 */
package de.artifacts.multitouch.behaviours
{
	import de.artifacts.multitouch.Cursor;
	import de.artifacts.multitouch.TouchEvent;
	import de.artifacts.multitouch.TouchManager;
	
	import flash.display.DisplayObject;
	
	public class BringToFrontOnTouchBehaviour extends TouchBehaviour
	{
		public var hotSpotX : Number;
		public var hotSpotY : Number;		
		
		public function BringToFrontOnTouchBehaviour()
		{
			super();
		}

		override public function touchedHandler(event : TouchEvent) : void
		{
			super.touchedHandler(event);
						
			if (cursor!=null && cursor.touchables.indexOf(touchable)==0) // only bring touchable to front if it's the first one hit by the cursor
			{												
				var topMostChild : DisplayObject = touchable.wrappee.parent.getChildAt(touchable.wrappee.parent.numChildren-1);
				touchable.wrappee.parent.swapChildren(topMostChild, touchable.wrappee);
			}
			event.stopPropagation();			
		}
		
	}
}